
/********************************************************************
 created:	2017/05/26
 created:	16:10:2014   09:58
 filename:
 file path:
 file base:
 file ext:
 author:		chenyadong

 purpose:	CA 控件、插件js统一脚本
 *********************************************************************/


//密钥类型
var AT_KEYEXCHANGE = 1;
var AT_SIGNATURE = 2;

//算法类型
var ALG_RSA = 1;
var	ALG_SM2 = 2;

//证书解析项索引
var CERT_ITEM_PUBKEY = 1;  //1:公钥，返回base64格式
var	CERT_ITEM_ISSUER = 2;      //2:证书颁发者，返回如C=CN, S=jilin, L=changchun, O=CNC, OU=CNCCA, CN=CHINA NETCOM CLASS2 CA
var	CERT_ITEM_SUBJECT = 3;     //3:证书主题信息，返回如C=CN, S=江苏, L=WUXI, CN=TEST4
var	CERT_ITEM_BEFORE_TIME = 4; //4:证书生效日期，返回如2008-01-06 13:10:07
var	CERT_TIEM_AFTER_TIME = 5;  //5:证书失效日期，返回如2008-01-06 13:10:07
var	CERT_ITEM_SN = 6;          //6:证书序列号，返回如0983
var	CERT_ITEM_SUBJECT_CN = 7;  //7:证书subect中的CN项
var CERT_ITEM_ALGTYPE = 8;

//支持的签名算法
var	ALG_SIGN_RsaWithMD5 = 1;
var	ALG_SIGN_RsaWithSHA1 = 2;
var	ALG_SIGN_SM2WithSM3 = 3;

//支持的对称加解密算法
var ALG_SYM_DES = 1; //DES 算法
var	ALG_SYM_TDES = 2;   //3des算法
var	ALG_SYM_SM1 = 3;   //国密sm1算法
var	ALG_SYM_AES = 4;   //aes算法


//对于IE11的判断需要使用userAgent中的Trident进行判断
function isIE(){

	var isIEof11 = isIE11();
	var bisIE = checkBrowserISIE();
	return ((navigator.appName.indexOf("Microsoft Internet Explorer")!=-1 && document.all) || isIEof11 || bisIE);
}

function checkBrowserISIE()
{
	return (!!window.ActiveXObject || 'ActiveXObject' in window) ? true : false;
}
//IE11的判断已经不能使用MSIE来判断 userAgent：Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv 11.0) like Gecko
function isIE11(){
	var trident = navigator.userAgent.split(";")[2];
	var trident64 = navigator.userAgent.split(";")[3];

	if(trident == null && trident64 == null)
	{
		//alert("trident is null");
		return false;
	}

	var isx86 = false;
	var isx64 = false;

	if(trident != null)
	{
		isx86 = navigator.userAgent.split(";")[2].toLowerCase().indexOf("trident")=="-1"?false:true;
	}

	if(trident64 != null)
	{
		isx64 = navigator.userAgent.split(";")[3].toLowerCase().indexOf("trident")=="-1"?false:true;
	}

	return isx86 || isx64;
}

//====================关键信息:加载插件、控件==================================
//若是IE浏览器，则加载控件，若是其他浏览器，则加载插件
//IE64位加载插件需要确定是否可以
//=============================================================================
if(isIE()){
	if(typeof(zwPlugin) != 'object')
	{
		document.write('<object classid="CLSID:589F6929-9B41-4844-86FF-F61F0B35617C" style="display: none" id="zwPlugin">');
		document.write('</object>');
	}
}else{
	document.write('<object id="zwPlugin" type="application/x-zwplugin" style="display: none" width="0" height="0">');
	document.write('</object>');
}

//js中使用的插件对象
plugin = zwPlugin;

//获取插件对象
function zwPlugin()
{
	return document.getElementById('zwPlugin');
}

/********************http/https发送、接收信息****************************************/
var _xmlhttp;

function GetHttpResult() {
	if (_xmlhttp.readyState == 4 && _xmlhttp.status == 200) {
		var obj = eval("(" + _xmlhttp.responseText + ")");
		return obj;
	}
	else {
		return null;
	}
}

function AjaxIO(json_in) {
	try{
		var _url= "http://127.0.0.1:8198";
		var json = json_in;
		if (_xmlhttp == null) {
			if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
				_xmlhttp = new XMLHttpRequest();
			} else { // code for IE6, IE5
				_xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}

		if ("https:" == document.location.protocol) {
			_url = "https://127.0.0.1:8199";
		}

		_xmlhttp.open("POST", _url, false);
		_xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");


		_xmlhttp.send("json=" + json);
	}
	catch(e){
		alert("证书助手功能异常，请修复或重装");
	}
}


/*************************
 十进制转十六进制
 *****************************/
function dec2hex(decnum) {
	var hexcode;
	var hexnum = "0123456789ABCDEF";
	var n;
	n = 0;
	hexcode = "";
	while (n < 8) {
		i = decnum & 0x0000000F;
		hexcode = hexnum.substring(i, i + 1) + hexcode;
		decnum = decnum >> 4;
		n++;
	}

	hexcode = "0x" + hexcode;
	return hexcode;
}

/*****************************
 检测控件是否安装
 *******************************/
function CheckComSetup()
{
	try{
		if(!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "checkComSetup";
			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {

				return (ret.resultMSG==0)?true:false;
			}
		}
		else{
			plugin().CheckComSetup();
			alert("控件已经安装");
			this.blur();
			this.focus();
			return true;
		}
	}
	catch(e){
		alert("控件没有安装");
		this.blur();
		this.focus();
		return false;
	}
}

/************************************************************************/
/*    获取插件版本号                                                    */
/************************************************************************/
function getVersion()
{
	try{
		var version = "";

		if (!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "GetVersion";
			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("获取控件版本发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
				}
				return ret.resultMSG;
			}
		}
		else{
			version =  plugin().GetVersion();
			return version;
		}
	}
	catch(e){
		//alert("请安装控件！");
		this.blur();
		this.focus();
		return version;
	}
}

/************************************************************************/
/*    枚举密钥服务提供者                                                    */
/************************************************************************/
function enumProvider(listctl)
{
	try{
		var i;
		var element;

		while (listctl.length > 0)
		{
			listctl.remove(0);
		}

		if (!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "EnumProvider";
			request.iEnumType = 1;

			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("枚举设备发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
				}

				enumProvider_list(listctl, ret.resultMSG);
			}
		}
		else{
			var listProvider = plugin().EnumProvider(1);
			enumProvider_list(listctl, listProvider);
		}

	}catch(e)
	{
		if (e.description != "")
		{
			alert("列举设备发生错误!" + "\r\n" + "错误描述：" + e.description);
			this.blur();
			this.focus();
		}
		else
		{
			alert("列举设备失败!");
			this.blur();
			this.focus();
		}

	}
}

//枚举设备接口内部用方法
function enumProvider_list(listctl, listProvider)
{
	try{
		var jsArray = listProvider.split("#");

		var length = jsArray.length;

		var i = 0;

		while(i < length/2)
		{
			element = document.createElement("OPTION");
			element.text = jsArray[i*2];
			element.value = jsArray[i*2+1];
			listctl.add(element);
			i++;
		}

		if (listctl.length > 0)
		{
			listctl.selectedIndex = 0;
		}

		if(listctl.length == 0)
		{
			element = document.createElement("OPTION");

			element.value = -1;
			element.text = "请安装控件";
			listctl.add(element);
		}
	}
	catch(e)
	{
		if (e.description != "")
		{
			alert("列举设备发生错误!" + "\r\n" + "错误描述：" + e.description);
			this.blur();
			this.focus();
		}
		else
		{
			alert("列举设备失败!");
			this.blur();
			this.focus();
		}
	}
}
/************************************************************************/
/*    初始化服务提供者
/*  @param  provName
/*          CSP名称
/*  @param  contName
/*          容器名称
/*  @return 成功返回true， 失败返回false                                */
/************************************************************************/
function initProv(provName, contName)
{
	contName = contName || "CCITCont1";
	try{
		if (!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "InitProvider";
			request.provName = provName;
			request.contName = contName;

			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("初始化发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
				}

				return (ret.resultMSG == 0) ? true : false;
			}
		}
		else{
			var ret = plugin().InitProvider(provName, contName);
			return (ret == 0) ? true : false;
		}
	}
	catch(e){
		if (e.description != "")
		{
			// alert(e.description);
			this.blur();
			this.focus();
		}

		return false;
	}
}


/************************************************************************/
/*    初始化服务提供者
/*  @param  provName
/*          CSP名称
/*  @param  contName
/*          容器名称
/*  @return 成功返回true， 失败返回false                                */
/************************************************************************/
function InitProviderEX(provName)
{

	try{
		if (!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "InitProviderEX";
			request.provName = provName;

			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("初始化发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
				}

				return (ret.resultMSG == 0) ? true : false;
			}
		}
		else{
			var ret = plugin().InitProviderEX(provName);
			return (ret == 0) ? true : false;
		}
	}
	catch(e){
		if (e.description != "")
		{
			// alert(e.description);
			this.blur();
			this.focus();
		}

		return false;
	}
}

/************************************************************************/
/*    获取设备序列号 成功返回版本号，失败返回null                                                   */
/************************************************************************/
function readUKSN ()
{
	var ret;

	try{
		if (!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "readDeviceSN";

			AjaxIO(JSON.stringify(request));

			ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("获取设备序列号发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
					return null;
				}
				else{
					return ret.resultMSG;
				}

			}
		}
		else{
			ret = plugin().ReadDeviceSN();

			return ret;
		}
	}
	catch(e){

		if (e.description != "")
		{
			// alert(e.description);
			this.blur();
			this.focus();
		}

		return null;
	}
}

/************************************************************************/
/*   清除用户的登录状态 ，成功返回0                                                */
/************************************************************************/
function ClearUserPin()
{
	var ret;

	try{
		if (!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "ClearDevicePwd";
			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("清除用户口令发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
				}

				return ret.resultMSG;
			}
		}
		else{
			ret = plugin().ClearDevicePwd();
			return ret;
		}
	}
	catch(e){

		if (e.description != "")
		{
			alert(e.description);
			this.blur();
			this.focus();
		}

		return -1;
	}
}

/************************************************************************/
/*   修改用户的密码，若原密码错误，则提示可尝试次数
/*   @param oldPwd
/*          设备的当前密码
/*   @param newPwd
/*          设备的新密码
/*   @return 成功返回0，失败返回其他错误码                              */
/************************************************************************/
function changeUKPin(oldPwd, newPwd)
{
	try{
		if (!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "ChangeDevicePwd";
			request.oldPwd = oldPwd;
			request.newPwd = newPwd;

			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if(ret.errcode != 0)
				{
					if(ret.resultMSG > 0 && ret.resultMSG <= 10)
					{
						alert("您输入的当前密码错误，还剩" + ret.resultMSG + "次尝试机会！");
						this.blur();
						this.focus();
					}
					else{
						alert("修改密码发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
					}
					return dec2hex(ret.errcode);
				}
				else if(ret.resultMSG == 0)
				{
					alert("密码修改成功！");
					this.blur();
					this.focus();
					return ret.resultMSG;
				}
			}

		}
		else{
			var ret =  plugin().ChangeDevicePwd(oldPwd, newPwd);
			if(ret > 0 && ret <= 10)
			{

				alert("您输入的当前密码错误，还剩" + ret + "次尝试机会！");
				this.blur();
				this.focus();
			}
			else if(ret == 0)
			{
				alert("密码修改成功！");
				this.blur();
				this.focus();
			}

			return ret;
		}
	}
	catch(e){

		if (e.description != "")
		{
			alert(e.description);
			this.blur();
			this.focus();
		}

		return dec2hex(e.number);
	}
}

/************************************************************************/
/*   解锁用户的密码，若管理员密码错误，则提示可尝试次数
/*   @param pukPwd
/*          设备的当前sopin
/*   @param newPwd
/*          设备的新密码
/*   @return 成功返回0，失败返回其他错误码                              */
/************************************************************************/
function unblockUKPin(pukPwd, newPwd)
{
	try{
		if (!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "UnLockUserPwd";
			request.pukPwd = pukPwd;
			request.newPwd = newPwd;

			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if(ret.errcode != 0)
				{
					if(ret.resultMSG > 0 && ret.resultMSG <= 10)
					{
						alert("您输入的iPASS解锁密码错误，还剩" + ret.resultMSG + "次尝试机会！");
						this.blur();
						this.focus();
					}
					else{
						alert("解锁口令发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
					}

					return dec2hex(ret.errcode);
				}
				else if(ret.resultMSG == 0)
				{
					alert("解锁密码成功！");
					this.blur();
					this.focus();
					return ret.resultMSG;
				}
			}

		}
		else{
			ret = plugin().UnLockUserPwd(pukPwd, newPwd);
			if(ret > 0 && ret <= 10)
			{
				alert("您输入的iPASS解锁密码错误，还剩" + ret + "次尝试机会！");
				this.blur();
				this.focus();
			}
			else if(ret == 0)
			{
				alert("解锁密码成功！");
				this.blur();
				this.focus();
			}

			return ret;
		}
	}
	catch(e){

		if (e.description != "")
		{
			alert(e.description);
			this.blur();
			this.focus();
		}

		return dec2hex(e.number);
	}
}

/************************************************************************/
/*   解锁用户的密码，若管理员密码错误，则提示可尝试次数
/*   @param pukPwd
/*          设备的当前sopin的密文
/*   @param newPwd
/*          设备的新密码，若输入为空，则内容将修改为”000000“
/*   @return 成功返回0，失败返回其他错误码                              */
/************************************************************************/
function unblockUKPinEx(pukPwd, newPwd)
{
	try{
		if (!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "UnLockUserPwdEx";
			request.pukPwd = pukPwd;
			request.newPwd = newPwd;

			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if(ret.errcode != 0)
				{
					if(ret.resultMSG > 0 && ret.resultMSG <= 10)
					{
						alert("您输入的iPASS解锁密码错误，还剩" + ret.resultMSG + "次尝试机会！");
						this.blur();
						this.focus();
					}
					else{
						alert("解锁口令发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
					}

					return dec2hex(ret.errcode);
				}
				else if(ret.resultMSG == 0)
				{
					alert("解锁密码成功！");
					this.blur();
					this.focus();
					return ret.resultMSG;
				}
			}
		}
		else{
			var ret = plugin().UnLockUserPwdEx(pukPwd, newPwd);
			if(ret > 0 && ret <= 10)
			{
				alert("您输入的iPASS解锁密码错误，还剩" + ret + "次尝试机会！");
				this.blur();
				this.focus();
			}
			else if(ret == 0)
			{
				alert("解锁密码成功！");
				this.blur();
				this.focus();
			}

			return ret;
		}
	}
	catch(e){

		if (e.description != "")
		{
			alert(e.description);
			this.blur();
			this.focus();
		}

		return -1;
	}
}

/************************************************************************/
/*   删除指定的容器
/*   @param contName
/*          指定的容器名称
/*   @return 成功返回0，失败返回其他错误码                              */
/************************************************************************/
function DeleteContainer(contName)
{
	try{
		if (!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "DeleteContainer";
			request.contName = contName;

			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("删除容器发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
				}

				return dec2hex(ret.resultMSG);
			}
		}
		else{
			var ret = plugin().DeleteContainer(contName);
			return ret;
		}

	}
	catch(e){

		if (e.description != "")
		{
			alert(e.description);
			this.blur();
			this.focus();
		}

		return dec2hex(e.number);
	}
}

/************************************************************************/
/*   根据不同的模长生成不同的密钥对，容器使用初始化时候的容器
/*   @param module
/*          模长，256-sm2  1024/2048-rsa
/*   @return 成功返回base64的公钥，失败返回null                   */
/************************************************************************/
function createPubKey (module)
{
	try{
		if (!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "CreatePubKey";
			request.module = module;
			request.iKeyType = AT_SIGNATURE;
			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("生成密钥对发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
					return null;
				}
				else{
					return ret.resultMSG;
				}
			}
		}
		else{
			var pubkey = plugin().CreatePubKey(module, AT_SIGNATURE);
			return pubkey;
		}
	}
	catch(e){

		if (e.description != "")
		{
			// alert(e.description);
			this.blur();
			this.focus();
		}

		return null;
	}
}

/************************************************************************/
/*   生成临时的RSA密钥对，容器名称内部处理
/*   @param keySpec
/*          密钥类型，AT_SINAGURE/AT_KEYEXCHANGE
/*   @param module
/*          模长，1024/2038-rsa
/*   @return 成功返回base64的公钥，失败返回null               */
/************************************************************************/
function GenTempRsaKeyPairWithKeySpec(keySpec, module)
{
	try{
		if(!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "CreateTempKeyPair";
			request.type = ALG_RSA;
			request.keySpec = keySpec;
			request.module = module;
			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("生成临时密钥发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
					return null;
				}
				else{
					return ret.resultMSG;
				}
			}
		}
		else{
			var ret =  plugin().CreateTempKeyPair(ALG_RSA, keySpec, module);
			return ret;
		}

	}
	catch(e){

		if (e.description != "")
		{
			alert(e.description);
			this.blur();
			this.focus();
		}

		return null;

	}
}

/************************************************************************/
/*   生成临时的SM2密钥对，容器名称内部处理
/*   @param keySpec
/*          密钥类型，AT_SINAGURE/AT_KEYEXCHANGE
/*   @param module
/*          模长，256
/*   @return 成功返回base64的公钥，失败返回null               */
/************************************************************************/
function GenTempSM2KeyPairWithKeySpec(keySpec, module)
{
	try{
		if(!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "CreateTempKeyPair";
			request.type = ALG_SM2;
			request.keySpec = keySpec;
			request.module = module;
			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("生成临时密钥对发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
					return null;
				}
				else{
					return ret.resultMSG;
				}
			}
		}
		else{
			var ret =  plugin().CreateTempKeyPair(ALG_SM2, keySpec, module);
			return ret;
		}

	}
	catch(e){

		if (e.description != "")
		{
			alert(e.description);
			this.blur();
			this.focus();
		}

		return null;

	}
}

/************************************************************************/
/*   下载单证书
/*   @param packdata
/*          base64格式的证书数据
/*   @param transactionId
/*          交易码，没有实际用处
/*   @return 成功返回true,失败返回false                                 */
/************************************************************************/
function downloadSingle(packdata, transactionId)
{
	try{
		if(!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "DownloadSingleCert";
			request.packdata = packdata;
			request.transactionId = transactionId;

			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("下载单证书发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
				}

				return (ret.resultMSG==0)? true:false;
			}
		}
		else
		{
			if(plugin().DownloadSingleCert(packdata, transactionId) == 0)
				return true;
			else
				return false;
		}
	}
	catch(e){

		if (e.description != "")
		{
			// alert(e.description);
			this.blur();
			this.focus();
		}

		return false;
	}
}

/************************************************************************/
/*   下载双证书
/*   @param packdata
/*          base64格式的证书数据包，包括三部分，以“    ”分隔，
/*                       分别为签名证书+加密证书+加密私钥
/*   @param transactionId
/*          交易码，没有实际用处
/*   @return 成功返回true,失败返回false                                 */
/************************************************************************/
function downloadDouble(packdata, transactionId)
{
	try{
		if(!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "downloadDouble";
			request.packdata = packdata;
			request.transactionId = transactionId;
			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("下载双证书发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
				}

				return (ret.resultMSG==0)? true:false;
			}
		}
		else{
			if(plugin().DownloadDoubleCert(packdata, transactionId) == 0)
			{
				return true;
			}else{
				return false;
			}
		}

	}
	catch(e){

		if (e.description != "")
		{
			// alert(e.description);
			this.blur();
			this.focus();
		}

		return false;
	}
}

/************************************************************************/
/*   加密证书恢复
/*   @param packdata
/*          base64格式的证书数据包，包括两部分，以“    ”分隔，
/*                       分别为加密证书+加密私钥
/*   @param transactionId
/*          交易码，没有实际用处
/*   @return 成功返回true,失败返回false                                 */
/************************************************************************/
function restoreKey (packdata, transactionId)
{
	try{
		if(!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "RestoreCert";
			request.packdata = packdata;
			request.transactionId = transactionId;
			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("密钥恢复发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
				}

				return (ret.resultMSG == 0) ? true:false;
			}
		}
		else{
			if(plugin().RestoreCert(packdata, transactionId) == 0)
			{
				return true;
			}else{
				return false;
			}
		}

	}
	catch(e){

		if (e.description != "")
		{
			alert(e.description);
			this.blur();
			this.focus();
		}

		return false;
	}
}

/************************************************************************/
/*   证书解析：获取证书公钥
/*   @param base64Cert
/*          base64格式的证书数据
/*   @return 成功返回base64格式公钥,失败返回null                       */
/************************************************************************/
function getCertPubKey(base64Cert)
{
	var ret;

	try{

		if(!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "getCertItemInfo";
			request.base64Cert = base64Cert;
			request.iCertItemType = CERT_ITEM_PUBKEY;
			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("获取证书公钥发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
					return null;
				}
				else{
					return ret.resultMSG;
				}
			}
		}
		else{
			ret = plugin().getCertItemInfo(base64Cert, CERT_ITEM_PUBKEY);
			return ret;
		}
	}
	catch(e){

		if (e.description != "")
		{
			// alert(e.description);
			this.blur();
			this.focus();
		}


		return null;
	}
}


/************************************************************************/
/*   证书解析：获取证书类型RSA、SM2
/*   @param base64Cert
/*          base64格式的证书数据
/*   @return 成功返回RSA或SM2，失败返回null                       */
/************************************************************************/
function getCertType(base64Cert)
{
	var ret;

	try{
		if(!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "getCertItemInfo";
			request.base64Cert = base64Cert;
			request.iCertItemType = CERT_ITEM_ALGTYPE;
			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("获取证书类型发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
					return null;
				}
				else{
					return ret.resultMSG;
				}
			}
		}
		else{
			ret = plugin().getCertItemInfo(base64Cert, CERT_ITEM_ALGTYPE);
			return ret;
		}
	}
	catch(e){

		if (e.description != "")
		{
			alert(e.description);
			this.blur();
			this.focus();
		}

		return null;
	}
}

/************************************************************************/
/*   证书解析：获取证书颁发者信息
/*   @param base64Cert
/*          base64格式的证书数据
/*   @return 成功返回C=CN, S=jilin, L=changchun, O=CNC, OU=CNCCA,
/*                   CN=CHINA NETCOM CLASS2 CA,失败返回null           */
/************************************************************************/
function getCertIssuer(base64Cert)
{
	var ret;

	try{
		if(!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "getCertItemInfo";
			request.base64Cert = base64Cert;
			request.iCertItemType = CERT_ITEM_ISSUER;
			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("获取证书颁发者发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
					return null;
				}
				else{
					return ret.resultMSG;
				}
			}
		}
		else{
			ret = plugin().getCertItemInfo(base64Cert, CERT_ITEM_ISSUER);
			return ret;
		}
	}
	catch(e){

		if (e.description != "")
		{
			// alert(e.description);
			this.blur();
			this.focus();
		}

		return null;
	}
}

/************************************************************************/
/*   证书解析：获取证书主题项
/*   @param base64Cert
/*          base64格式的证书数据
/*   @return 成功返回C=CN, S=江苏, L=WUXI, CN=TEST4,失败返回null     */
/************************************************************************/
function getCertSubject(base64Cert)
{
	var ret;

	try{

		if(!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "getCertItemInfo";
			request.base64Cert = base64Cert;
			request.iCertItemType = CERT_ITEM_SUBJECT;
			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("获取证书主题项发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
					return null;
				}
				else{
					return ret.resultMSG;
				}
			}
		}
		else{
			ret = plugin().getCertItemInfo(base64Cert, CERT_ITEM_SUBJECT);
			return ret;
		}

	}
	catch(e){

		if (e.description != "")
		{
			// alert(e.description);
			this.blur();
			this.focus();
		}


		return null;
	}
}

/************************************************************************/
/*   证书解析：获取证书生效时间
/*   @param base64Cert
/*          base64格式的证书数据
/*   @return 成功返回2008-01-06 13:10:07格式日期,失败返回null        */
/************************************************************************/
function getCertNotBefore (base64Cert)
{
	var ret;

	try{
		if(!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "getCertItemInfo";
			request.base64Cert = base64Cert;
			request.iCertItemType = CERT_ITEM_BEFORE_TIME;
			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("获取证书生效时间发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
					return null;
				}
				else{
					return ret.resultMSG;
				}
			}
		}
		else{
			ret = plugin().getCertItemInfo(base64Cert, CERT_ITEM_BEFORE_TIME);
			return ret;
		}
	}
	catch(e){

		if (e.description != "")
		{
			// alert(e.description);
			this.blur();
			this.focus();
		}

		return null;
	}
}

/************************************************************************/
/*   证书解析：获取证书失效时间
/*   @param base64Cert
/*          base64格式的证书数据
/*   @return 成功返回2008-01-06 13:10:07格式日期,失败返回null        */
/************************************************************************/
function getCertNotAfter(base64Cert)
{
	var ret;

	try{
		if(!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "getCertItemInfo";
			request.base64Cert = base64Cert;
			request.iCertItemType = CERT_TIEM_AFTER_TIME;
			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("获取证书失效时间发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
					return null;
				}
				else{
					return ret.resultMSG;
				}
			}
		}
		else{
			ret = plugin().getCertItemInfo(base64Cert, CERT_TIEM_AFTER_TIME);
			return ret;
		}
	}
	catch(e){

		if (e.description != "")
		{
			// alert(e.description);
			this.blur();
			this.focus();
		}
		return null;
	}
}

/************************************************************************/
/*   证书解析：获取证书序列号
/*   @param base64Cert
/*          base64格式的证书数据
/*   @return 成功返回0983格式日期,失败返回null                          */
/************************************************************************/
function getCertSN(base64Cert)
{
	var ret;

	try{
		if(!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "getCertItemInfo";
			request.base64Cert = base64Cert;
			request.iCertItemType = CERT_ITEM_SN;
			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("获取证书序列号发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
					return null;
				}
				else{
					return ret.resultMSG;
				}
			}
		}
		else{
			ret = plugin().getCertItemInfo(base64Cert, CERT_ITEM_SN);
			return ret;
		}
	}
	catch(e){

		if (e.description != "")
		{
			// alert(e.description);
			this.blur();
			this.focus();
		}

		return null;
	}
}

/************************************************************************/
/*   证书解析：获取证书扩展项信息
/*   @param base64Cert
/*          base64格式的证书数据
/*   @param extensionID
/*          扩展项的OID
/*   @return 成功返回扩展项信息,失败返回null                            */
/************************************************************************/
function getCertExtension (base64Cert, extensionID)
{
	var ret;

	try{
		if(!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "getCertExtension";
			request.base64Cert = base64Cert;
			request.extensionID = extensionID;
			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("获取证书扩展项发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
					return null;
				}
				else{
					return ret.resultMSG;
				}
			}
		}
		else{
			ret =  plugin().getCertExtensionInfo(base64Cert, extensionID);
			return ret;
		}
	}
	catch(e){

		if (e.description != "")
		{
			// alert(e.description);
			this.blur();
			this.focus();
		}

		return null;
	}
}

/************************************************************************/
/*   获取随机数
/*   @param randomLen
/*          要获取的随机数长度
/*   @return 成功返回base64格式的随机数,失败返回null                    */
/************************************************************************/
function genRandom (randomLen)
{
	try{
		if(!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "genRandom";
			request.randomLen = randomLen;
			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("生成随机数发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
					return null;
				}
				else{
					return ret.resultMSG;
				}
			}
		}else{
			var ret =  plugin().genRandom(randomLen);
			return ret;
		}
	}
	catch(e){

		if (e.description != "")
		{
			alert(e.description);
			this.blur();
			this.focus();
		}

		return null;
	}
}

/************************************************************************/
/*   从指定的容器中获取证书
/*   @param containerName
/*          容器名称
/*   @param iKeyType
/*          容器类型
/*   @return 成功返回base64格式的证书,失败返回null                      */
/************************************************************************/
function getCert(containerName, iKeyType)
{
	try{
		var certdata = "";

		if(!isIE())
		{
			// alert(listProvider);
			// 调用接口
			var request = new Object();
			request.method = "getCertByContName";
			request.containerName = containerName;
			request.iKeyType = iKeyType;
			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("读取证书发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
					return null;
				}
				else{
					return ret.resultMSG;
				}
			}
		}
		else{
			certdata = plugin().getCertByContName(containerName, iKeyType);
			return certdata;
		}
	}
	catch(e){

		if (e.description != "")
		{
			// alert(e.description);
			this.blur();
			this.focus();
		}

		return null;
	}
}

/************************************************************************/
/*   对源数据使用指定的签名算法进行签名
/*   @param srcData
/*          源数据
/*   @pram AlgType
/*         签名算法，见ALG_SIGN_XXX定义
/*   @return 成功返回base64格式的签名内容,失败返回null                  */
/************************************************************************/
function signatureWithAlg (srcData, AlgType)
{
	try{
		var signdata;

		if(!isIE())
		{
			// alert(listProvider);
			// 调用接口
			var request = new Object();
			request.method = "sign";
			request.srcData = srcData;
			request.AlgType = AlgType;
			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("数字签名发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
					return null;
				}
				else{
					return ret.resultMSG;
				}
			}
		}
		else{
			signdata = plugin().sign(srcData, AlgType);
			return signdata;
		}

	}
	catch(e){

		if (e.description != "")
		{
			// alert(e.description);
			this.blur();
			this.focus();
		}

		return null;
	}
}

/************************************************************************/
/*   使用证书对签名数据进行验签
/*   @param srcData
/*          源数据
/*   @param signData
/*          签名数据
/*   @param certData
/*          证书数据，base64格式
/*   @pram iSignAlg
/*         签名算法，参见ALG_SIGN_XXX定义
/*   @return 成功返回true,失败返回false                                 */
/************************************************************************/
function verifySign (srcData, signData, certData, iSignAlg)
{
	var ret = false;

	try{
		if(!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "verifySignWithCert";
			request.srcData = srcData;
			request.signData = signData;
			request.certData = certData;
			request.iSignAlg = iSignAlg;

			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("验证签名发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
				}

				return (ret.resultMSG == 0) ? true :  false;
			}
		}
		else{
			ret = plugin().verifySignWithCert(srcData, signData, certData, iSignAlg);
			return (ret == 0) ? true :  false;
		}

	}
	catch(e){

		if (e.description != "")
		{
			// alert(e.description);
			this.blur();
			this.focus();
		}
		return false;
	}
}

/************************************************************************/
/*   使用公钥对签名数据进行验签
/*   @param srcData
/*          源数据
/*   @param signData
/*          签名数据
/*   @param pubKey
/*          公钥数据，base64格式
/*   @pram iSignAlg
/*         签名算法，参见ALG_SIGN_XXX定义
/*   @return 成功返回true,失败返回false                                 */
/************************************************************************/
function verifyWithAlg (srcData, signData, pubKey, iSignAlg)
{
	var ret = -1;

	try{

		if(!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "verifySign";
			request.srcData = srcData;
			request.signData = signData;
			request.iSignAlg = iSignAlg;
			request.pubKey = pubKey;

			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("验证签名发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
				}

				return (ret.resultMSG == 0) ? true : false;
			}
		}
		else{
			ret = plugin().verifySign(srcData, signData, iSignAlg, pubKey);
			return (ret == 0) ? true : false;
		}
	}
	catch(e){

		if (e.description != "")
		{
			// alert(e.description);
			this.blur();
			this.focus();
		}
		return false;
	}
}

/************************************************************************/
/*   使用内部私钥对文件进行签名，
/*   @param fileName
/*          文件绝对路径
/*   @pram iSignAlg
/*         签名算法，参见ALG_SIGN_XXX定义
/*   @return 成功返回base64签名值，失败返回null                               */
/************************************************************************/
function signFile (filePath,nAlg)
{
	try{
		if(!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "signFile";
			request.filePath = filePath;
			request.algType = nAlg;
			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("文件签名发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
					return null;
				}
				else{
					return ret.resultMSG;
				}
			}
		}
		else{
			var ret = plugin().signFile(filePath, nAlg);
			return ret;
		}

	}
	catch(e){

		if (e.description != "")
		{
			alert(e.description);
			this.blur();
			this.focus();
		}

		return null;
	}
}

/************************************************************************/
/*   使用外部公钥对文件进行验签
/*   @param fileName
/*          文件绝对路径
/*   @pram iSignAlg
/*         签名算法，参见ALG_SIGN_XXX定义
/*   @return 成功返回true,失败返回false                                 */
/************************************************************************/
function verifyFileSignature(filePath, signData, pubKey,nAlg)
{
	try{
		if(!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "verifySignFile";
			request.filePath = filePath;
			request.signData = signData;
			request.pubKey = pubKey;
			request.algType = nAlg;
			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("枚举设备发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
				}

				return (ret.resultMSG==0) ? true:false;
			}
		}
		else{
			if(plugin().verifySignFile(filePath, signData, pubKey, nAlg) == 0)
			{
				return true;
			}else{
				return false;
			}
		}

	}
	catch(e){

		if (e.description != "")
		{
			alert(e.description);
			this.blur();
			this.focus();
		}

		return false;
	}
}

/************************************************************************/
/*   北六项目定制接口：对源数据使用指定的SHA1签名算法进行签名
/*   @param srcData
/*          源数据
/*   @return 成功返回base64格式的签名内容,失败返回null                  */
/************************************************************************/
function signatureEx(srcData)
{
	try{
		if(!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "signForESS";
			request.srcData = srcData;

			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("数字签名发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
					return null;
				}
				else{
					return ret.resultMSG;
				}
			}
		}
		else{
			return  plugin().signForESS(srcData);
		}
	}
	catch(e){

		if (e.description != "")
		{
			alert(e.description);
			this.blur();
			this.focus();
		}

		return null;
	}
}
/************************************************************************/
/*   自定义格式的数字信封
/*       格式定义：算法（4个字节）+加密后数据长度（4个字节）+加密后数据+加密后密钥长度（4个字)+加密后的密钥
/*   @param types
/*          0：代表是文件；1：代表的是数据
/*   @pram srcData
/*         当types==0表示的是文件名称，全路径
/*   @param certData
/*         base64编码的证书，接受者证书；对于双证书模式，应该是用加密证书
/*   @param outPath
/*         当types等于0时候有效，表示数字信封文件全路径
/*   @return  	当types==0,成功返回0,失败返回错误码
				当types不等于0，成功返回base64编码信封数据，失败返回""	*/
/************************************************************************/
function makeEnvelope (types, srcData, certData, outPath)
{
	try{
		if(!isIE())
		{
			// 调用接口
			var request = new Object();
			if(types == 0)
			{
				request.method = "makeEnvelopForFile";
				request.inFilePath = srcData;
				request.certData = certData;
				request.outPath = outPath;
			}
			else{
				request.method = "makeEnvelopForData";
				request.srcData = srcData;
				request.certData = certData;
			}

			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("解信封发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
				}

				return ret.resultMSG;
			}
		}
		else{
			if(types == 0){
				return plugin().makeEnvelopForFile(srcData, certData, outPath);
			}
			else{
				return plugin().makeEnvelopForData(srcData, certData);
			}

		}
	}
	catch(e){

		if (e.description != "")
		{
			alert(e.description);
			this.blur();
			this.focus();
		}

		if(types == 0)
		{
			return e.number;
		}
		else{
			return "";
		}
	}
}

/************************************************************************/
/*   自定义格式的数字信封解封操作
/*       格式定义：算法（4个字节）+加密后数据长度（4个字节）+加密后数据+加密后密钥长度（4个字)+加密后的密钥
/*   @param types
/*          0：代表的是文件
/*   @param evpData
/*          当types=0时代表信封文件
/*   @param outPath
/*          当types等于0时代表明文文件
/*
/*   @return 当types=0时成功返回0,失败返回错误码
			当types不等于0时，成功返回明文数据，失败返回"" */
/************************************************************************/
function openEnvelope (types, evpData, outPath)
{
	try{
		if(!isIE())
		{
			// 调用接口
			var request = new Object();
			if(types == 0)
			{
				request.method = "openEnvelopForFile";
				request.inPath = evpData;
				request.outPath = outPath;
			}
			else{
				request.method = "openEnvelopForData";
				request.evpData = evpData;
			}

			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("解信封发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
				}

				return ret.resultMSG;
			}
		}
		else{

			if(types == 0){
				return plugin().openEnvelopForFile(evpData, outPath);
			}
			else{
				return plugin().openEnvelopForData(evpData);
			}
		}
	}
	catch(e){

		if (e.description != "")
		{
			alert(e.description);
			this.blur();
			this.focus();
		}

		if(types == 0)
		{
			return e.number;
		}
		else{
			return "";
		}
	}
}

/************************************************************************/
/*   对称加密
/*   @param symAlg
/*          对称加密算法，参见ALG_SYM_XXX的定义
/*   @param srcData
/*          源数据
/*   @param keyData
/*          对称密钥，base64格式
/*   @return 成功返回base64格式密码,失败返回null                        */
/************************************************************************/
function 	symEncrypt(symAlg, srcData, keyData)
{
	try{
		if(!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "symEncrypt";
			request.symAlg = symAlg;
			request.srcData = srcData;
			request.keyData = keyData;
			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("对称加密发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
					return null;
				}
				else{
					return ret.resultMSG;
				}
			}
		}else{
			var ret = plugin().symEncrypt(srcData, keyData, symAlg);
			return ret;
		}

	}
	catch(e){

		if (e.description != "")
		{
			alert(e.description);
			this.blur();
			this.focus();
		}

		return null;
	}
}


/************************************************************************/
/*   对称解密
/*   @param symAlg
/*          对称加密算法，参见ALG_SYM_XXX的定义
/*   @param encData
/*          密文数据
/*   @param keyData
/*          对称密钥，base64格式
/*   @return 成功返回明文数据,失败返回null                              */
/************************************************************************/
function 	symDecrypt(symAlg, encData, keyData)
{
	try{
		if(!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "symDecrypt";
			request.symAlg = symAlg;
			request.encData = encData;
			request.keyData = keyData;
			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("对称解密发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
					return null;
				}
				else{
					return ret.resultMSG;
				}
			}
		}
		else{
			var ret = plugin().symDecrypt(encData, keyData, symAlg);

			return ret;
		}

	}
	catch(e){

		if (e.description != "")
		{
			alert(e.description);
			this.blur();
			this.focus();
		}

		return null;
	}
}

/************************************************************************/
/*   修改软证书的密码，对应的软证书为初始化时指定的软证书
/*   @param oldPin
/*          软证书的当前密码
/*   @param newPin
/*          软证书的新密码
/*   @return 成功返回true,失败返回false                                 */
/************************************************************************/
function ChangeUsrPin(oldPin, newPin)
{
	try{
		if(!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "changeSoftCertPwd";
			request.oldPin = oldPin;
			request.newPin = newPin;

			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("修改软证书密码发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
				}

				return (ret.resultMSG==0)?true:false;
			}
		}else{
			if(plugin().changeSoftCertPwd(oldPin, newPin) == 0)
			{
				return true;
			}else{
				return false;
			}
		}
	}
	catch(e){

		if (e.description != "")
		{
			alert(e.description);
			this.blur();
			this.focus();
		}

		return false;
	}
}

/************************************************************************/
/*   修改软证书的存储位置
/*   @param path
/*          软证书的新位置
/*   @return 成功返回true,失败返回false                                 */
/************************************************************************/
function setSoftCertPath (path)
{
	try{
		if(!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "setSoftCertNewPath";
			request.path = path;

			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("修改软证书位置发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
				}

				return (ret.resultMSG==0)?true:false;
			}
		}else{
			if(plugin().setSoftCertNewPath(path) == 0){
				return true;
			}else{
				return false;
			}
		}
	}
	catch(e){

		if (e.description != "")
		{
			alert(e.description);
			this.blur();
			this.focus();
		}

		return false;
	}
}

/**********************************************
 封装p7数字信封
 Plain：原文
 signAlg：签名算法，参见ALG_SIGN_XXX定义
 ReceiverCert：接收者证书，base64编码
 返回值：成功返回base64编码信封数据，失败返回null
 *************************************************/
function MakeP7Env(Plain, signAlg, ReceiverCert)
{

	try{
		if(!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "P7MakeEnvelope";
			request.Plain = Plain;
			request.signAlg = signAlg;
			request.ReceiverCert = ReceiverCert;

			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("生成P7信封发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
					return null;
				}
				else{
					return ret.resultMSG;
				}
			}
		}
		else{
			return plugin().P7MakeEnvelope(Plain, signAlg, ReceiverCert);
		}
	}
	catch(e){

		if (e.description != "")
		{
			alert(e.description);
			this.blur();
			this.focus();
		}
	}

	return null;
}

/**************************************************
 解p7信封
 EnvelopeData：base64编码p7信封
 nAlg：签名算法，参见ALG_SIGN_XXX定义
 返回值：成功返回明文数据，失败返回null
 ****************************************************/
function OpenP7Env(EnvelopeData, nAlg)
{
	try{
		if(!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "P7OpenEnvelope";
			request.EnvelopeData = EnvelopeData;
			request.nAlg = nAlg;

			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("解P7信封发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
					return null;
				}
				else{
					return ret.resultMSG;
				}
			}
		}
		else{

			return plugin().P7OpenEnvelope(EnvelopeData, nAlg);
		}
	}
	catch(e){

		if (e.description != "")
		{
			alert(e.description);
			this.blur();
			this.focus();
		}

		return null;
	}
}

/****************************************
 p7数字签名
 Plain：原文
 nAlg：签名算法，参见ALG_SIGN_XXX定义
 返回值：成功返回base64格式p7签名值，失败返回null
 *********************************************/
function P7Signature(Plain, nAlg)
{
	try{
		if(!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "P7Sign";
			request.Plain = Plain;
			request.nAlg = nAlg;

			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("P7签名发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
					return null;
				}
				else{
					return ret.resultMSG;
				}
			}
		}
		else{
			return plugin().P7Sign(Plain, nAlg);
		}
	}
	catch(e){

		if (e.description != "")
		{
			alert(e.description);
			this.blur();
			this.focus();
		}
	}

	return null;
}

/*********************************************
 验证p7签名
 Plain：原文
 SignData：p7格式签名值
 nAlg：签名算法，参见ALG_SIGN_XXX定义
 返回值：成功返回true，失败返回false
 ***************************************************/
function VerifyP7Signature(Plain, SignData, nAlg)
{

	try{
		if(!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "P7VerifySign";
			request.Plain = Plain;
			request.SignData = SignData;
			request.nAlg = nAlg;
			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("P7验签发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
				}

				return (ret.resultMSG==0)?true : false;
			}
		}
		else{
			if(plugin().P7VerifySign(Plain, SignData, nAlg) == 0){
				return true;
			}
		}
	}
	catch(e){

		if (e.description != "")
		{
			alert(e.description);
			this.blur();
			this.focus();
		}
		return false;
	}
}

/************************************************
 外部证书加密
 srcData:原文
 certData：base64格式证书数据
 返回值：成功返回base64格式密文，失败返回null
 *************************************************/
function EncryptWithCert(srcData, certData)
{
	try{
		if(!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "EncryptWithCert";
			request.srcData = srcData;
			request.certData = certData;
			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("证书加密发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
					return null;
				}
				else{
					return ret.resultMSG;
				}
			}
		}
		else{
			var ret = plugin().EncryptWithCert(srcData, certData);
			return ret;
		}
	}
	catch(e){

		if (e.description != "")
		{
			alert(e.description);
			this.blur();
			this.focus();
		}
		return null;
	}
}

/**************************************
 内部私钥解密
 cipherData：base64格式密文
 返回值：成功返回明文数据，失败返回null
 ***************************************/
function AsymDecrypt(cipherData)
{
	try{
		if(!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "AsymDecrypt";
			request.cipherData = cipherData;
			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("解密数据发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
					return null;
				}
				else{
					return ret.resultMSG;
				}
			}
		}
		else{
			var ret = plugin().AsymDecrypt(cipherData);
			return ret;
		}
	}
	catch(e){

		if (e.description != "")
		{
			alert(e.description);
			this.blur();
			this.focus();
		}

		return null;
	}

}

/***************************************
 将数据写入Ukey中的指定文件中
 srcData：待写入数据，可见字符串或base64编码格式字符串
 fileID：文件ID，整型
 返回值：成功返回true，失败返回false
 ****************************************/
function WriteDataToUKey(srcData, fileID)
{
	try{
		if(!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "WriteDataToUKey";
			request.srcData = srcData;
			request.fileID = fileID;
			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {

				return (ret.resultMSG==0)?true:false;
			}
		}
		else{
			if(plugin().WriteDataToUKey(srcData, fileID) == 0){
				return true;
			}
		}

	}
	catch(e){

		if (e.description != "")
		{
			alert(e.description);
			this.blur();
			this.focus();
		}
	}

	return false;
}

/*****************************************
 读取Ukey中指定文件中的数据
 fileID：文件ID，整型
 返回值：成功返回读取到的数据，失败返回null
 ********************************************/
function ReadDataFromUKey(fileID)
{
	try{
		if(!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "ReadDataFromUkey";
			request.fileID = fileID;
			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("读取Ukey文件发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
					return null;
				}
				else{
					return ret.resultMSG;
				}
			}
		}
		else{
			return plugin().ReadDataFromUkey(fileID);
		}
	}
	catch(e){

		if (e.description != "")
		{
			alert(e.description);
			this.blur();
			this.focus();
		}
	}

	return null;
}

/*****************************************
 获取已插入Ukey的CSP名称
 如果插入多支key，只获取识别到的第一支key
 成功返回Ukey的CSP名称，失败返回""
 **********************************************/
function getCSPNamebypid()
{
	try
	{
		if(!isIE())
		{
			// 调用接口
			var request = new Object();
			request.method = "GetCspNameByPID";
			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("获取CSP名称发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
				}

				return ret.resultMSG;
			}
		}
		else{
			var cspname;
			var ret;
			cspname = plugin().GetCspNameByPID();
			if(cspname == "")
			{
				ret = plugin().InitProvider("CCIT Smartcard CSP V1.0", "CCITCont1");
				if(ret == 0)
				{
					cspname = "CCIT Smartcard CSP V1.0";
				}
			}
			return cspname;
		}
	}
	catch(e){
		if (e.description != "")
		{
			try{
				ret = plugin().InitProvider("CCIT Smartcard CSP V1.0", "CCITCont1");
				if(ret == 0)
				{
					cspname = "CCIT Smartcard CSP V1.0";
					return cspname;
				}
			}
			catch(e)
			{
				return "";
			}
		}
		return "";
	}
}

/*******************************
 //判断是否插入key
 返回值：已插入返回1，未插入返回0
 *****************************************/
function isUKConnect()
{
	if(!isIE())
	{
		// 调用接口
		var request = new Object();
		request.method = "GetCspNameByPID";
		AjaxIO(JSON.stringify(request));

		var ret = GetHttpResult();
		if (ret) {


			return (ret.errcode==0) ? 1:0;
		}
	}
	else{
		try{
			var cspname = plugin().GetCspNameByPID();
			if(cspname == "")
			{
				ret = plugin().InitProvider("CCIT Smartcard CSP V1.0", "CCITCont1");
				if(ret == 0)
				{
					cspname = "CCIT Smartcard CSP V1.0";
				}
			}

			if(cspname == "")
			{
				return 0;
			}
			else{
				return 1;
			}
		}
		catch(e){
			if (e.description != "")
			{
				try{
					ret = plugin().InitProvider("CCIT Smartcard CSP V1.0", "CCITCont1");
					if(ret == 0)
					{
						cspname = "CCIT Smartcard CSP V1.0";
						return 1;
					}
				}
				catch(e)
				{
					return 0;
				}
			}else{
				return 0;
			}
		}
	}
}

/*********************************************************
 展示证书详情
 cert：base64格式证书数据
 返回值：成功返回true，失败返回false
 **************************************************************/
function ViewCertInfo(cert)
{
	try{
		if(!isIE())
		{
			var request = new Object();
			request.method = "ViewCertInfo";
			request.certData = cert;

			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {


				return (ret.resultMSG==0)? true:false;
			}
		}
		else{
			if(plugin().ViewCertInfo(cert) == 0){
				return true;
			}
		}
	}
	catch(e){

		if (e.description != "")
		{
			// alert(e.description);
			this.blur();
			this.focus();
		}
	}

	return false;
}



/**************************************************
 选择签名证书，将签名证书所在容器置为当前容器。
 signCert:base64格式的签名证书数据
 返回值：成功返回0.失败返回错误码
 *******************************************************/
function selectSignCert(signCert)
{
	try{
		if(!isIE())
		{
			var request = new Object();
			request.method = "selectSignCert";
			request.certData = certData;

			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				return ret.resultMSG;
			}
		}
		else{
			var ret = 0;
			ret = plugin().selectSignCert(signCert);   // 查找相匹配的签名证书,目的是为了 设置 容器索引

			return ret;
		}

	}catch(e)
	{
		if (e.description != "")
		{
			alert("选择签名证书发生错误！" + "\r\n" + "错误描述：" + e.description);
		}
		else
		{
			alert("选择签名证书失败.");
		}
		return -1;
	}
}



/***********************
 [in]provName CSP名称
 certData 管理员证书内容 --base64编码，本接口根据certData内容选择相应设备进行操作。
 UserType 0 用户  1 管理员
 [retval]true--成功  false-失败
 [comments]根据管理员证书内容区分管理员key和用户key,当UserType传入0时初将用户设备置为当前设备，
 当UserType为1时置管理员设备为当前设备。调用本接口前不需要调用initProv接口
 ***************************************/
function SetCurrentDevice(provName, certData, UserType)
{
	var RetVal = false;

	try{
		RetVal = initProv(provName, "CCITCont1");
		if(!RetVal)
			return false;
		if(!isIE())
		{
			var request = new Object();
			request.method = "SetCurrentDevice";
			request.certData = certData;
			request.usrType = UserType;

			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if(ret.resultMSG == 0)
					return true;
				else
					return false;
			}
		}
		else{
			RetVal =  plugin().SetCurrentDevice(certData, UserType);
			if(RetVal != 0)
				return false;
			else
				return true;
		}

	}
	catch(e){
		if (e.description != "")
		{
			alert("发生错误！\r\n错误码:" + dec2hex(e.number) + "\r\n" + "错误描述：" + e.description);
		}
		else
		{
			alert("错误码:" + dec2hex(e.number));
		}
		return false;
	}
}


/************************************************************************/
/*   北六项目定制接口：设置用户信息，多用户情况下以::分隔
/*   @param usrList
/*          用户列表
/*   @return 成功返回true,失败返回false                                 */
/************************************************************************/
function setBindUsr (usrList)
{
	try{
		if(!isIE())
		{
			var request = new Object();
			request.method = "writeBindUser";
			request.usrList = usrList;

			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("设置用户信息发生错误！" + "\r\n" + "错误描述：" + ret.errMsg);
				}
				return (ret.resultMSG == 0)?true:false;
			}
		}
		else{
			if(plugin().writeBindUser(usrList) == 0)
			{
				return true;
			}
		}
	}
	catch(e){

		if (e.description != "")
		{
			alert(e.description);
			this.blur();
			this.focus();
		}
	}

	return false;

}

/************************************************************************/
/*   北六项目定制接口：获取用户信息列表信息，
/*                     若有多个用户，则弹出对话框让用户选择
/*   @return 成功返回用户名称,失败返回null                                 */
/************************************************************************/
function getBindUsr ()
{
	var ret = null;

	try{
		if(!isIE())
		{
			var request = new Object();
			request.method = "readBindUser";

			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("获取用户信息发生错误！" + "\r\n" + "错误描述：" + ret.errMsg);
					return null;
				}
				else{
					return ret.resultMSG;
				}
			}
		}
		else{
			ret = plugin().readBindUser();
			return ret;
		}

	}
	catch(e){

		if (e.description != "")
		{
			alert(e.description);
			this.blur();
			this.focus();
		}

		return null;
	}
}

/**********************************
 验证Ukey口令
 usrPin:Ukey口令
 成功返回true，失败返回false
 ************************************/
function VerifyPin(usrPin)
{
	try{
		if(!isIE())
		{
			var request = new Object();
			request.method = "VerifyPin";
			request.usrPin = usrPin;

			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					if(ret.resultMSG > 0 && ret.resultMSG <= 10)
					{

						alert("您输入的当前密码错误，还剩" + ret.resultMSG + "次尝试机会！");
						this.blur();
						this.focus();
					}
					else{
						alert("口令验证失败！" + "\r\n" + "错误描述：" + ret.errMsg);
					}
				}
				return (ret.resultMSG == 0)?true:false;
			}
		}
		else{
			var RetVal =  plugin().VerifyPin(usrPin);


			if(RetVal != 0)
			{
				if(RetVal > 0 && RetVal <= 10)
				{
					alert("您输入的当前密码错误，还剩" + RetVal + "次尝试机会！");
					this.blur();
					this.focus();
				}
				else{
					alert("口令验证失败！" + "\r\n" + "错误描述：" + ret.errMsg);
				}
				return false;
			}
			else{
				return true;
			}
		}
	}
	catch(e){
		if (e.description != "")
		{
			alert("验证口令发生错误！\r\n错误码:" + dec2hex(e.number) + "\r\n" + "错误描述：" + e.description);
		}
		else
		{
			alert("错误码:" + dec2hex(e.number));
		}
		return false;
	}
}


/**********************************
 检测Ukey中文件是否存在
 ulFileID:文件ID，整型
 成功返回true，失败返回false
 ************************************/
function CheckUKFile(ulFileID)
{
	try{
		if(!isIE())
		{
			var request = new Object();
			request.method = "CheckUKFile";
			request.ulFileID = ulFileID;

			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("错误描述：" + ret.errMsg);
				}
				return (ret.resultMSG == 0)?true:false;
			}
		}
		else{
			var RetVal =  plugin().CheckUKFile(ulFileID);
			if(RetVal != 0)
				return false;
			else
				return true;
		}

	}
	catch(e){
		if (e.description != "")
		{
			alert("检测Ukey文件是否存在发生错误！\r\n错误码:" + dec2hex(e.number) + "\r\n" + "错误描述：" + e.description);
		}
		else
		{
			alert("错误码:" + dec2hex(e.number));
		}
		return false;
	}
}


/**********************************
 删除Ukey中文件
 ulFileID:文件ID
 成功返回true，失败返回false
 ************************************/
function DeleteUKFile(ulFileID)
{
	try{
		if(!isIE())
		{
			var request = new Object();
			request.method = "DeleteUKFile";
			request.ulFileID = ulFileID;

			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("删除Ukey文件发生错误!" + "\r\n" + "错误描述：" + ret.errMsg);
				}
				return (ret.resultMSG == 0)?true:false;
			}
		}
		else{
			var RetVal =  plugin().DeleteUKFile(ulFileID);
			if(RetVal != 0)
				return false;
			else
				return true;
		}

	}
	catch(e){
		if (e.description != "")
		{
			alert("删除Ukey文件发生错误！\r\n错误码:" + dec2hex(e.number) + "\r\n" + "错误描述：" + e.description);
		}
		else
		{
			alert("错误码:" + dec2hex(e.number));
		}
		return false;
	}
}

/**********************************
 设置是否显示错误信息
 ulFlag:0-不显示，非零-显示
 成功返回true，失败返回false
 ************************************/
function SetDebug(ulFlag)
{
	try{
		if(!isIE())
		{
			var request = new Object();
			request.method = "SetDebug";
			request.ulFlag = ulFlag;

			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				return (ret.resultMSG == 0)?true:false;
			}
		}
		else{
			var RetVal =  plugin().SetDebug(ulFlag);
			if(RetVal != 0)
				return false;
			else
				return true;
		}

	}
	catch(e){
		if (e.description != "")
		{
			alert("发生错误！\r\n错误码:" + dec2hex(e.number) + "\r\n" + "错误描述：" + e.description);
		}
		else
		{
			alert("错误码:" + dec2hex(e.number));
		}
		return false;
	}
}

/**********************************
 根据证书类型读取相应证书
 iKeyType:签名证书：AT_SIGNATURE；加密证书：AT_KEYEXCHANGE
 algType：算法类型，1-RSA；2-SM2
 成功返回base64编码证书，失败返回null
 ************************************/
function getCertByType(iKeyType, algType)
{
	try{
		if(!isIE())
		{
			var request = new Object();
			request.method = "getCertByType";
			request.iKeyType = iKeyType;
			request.algType = algType;

			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("获取证书发生错误！" + "\r\n" + "错误描述：" + ret.errMsg);
					return null;
				}
				else{
					return ret.resultMSG;
				}
			}
		}
		else{
			var RetVal =  plugin().getCertByType(iKeyType, algType);

			return RetVal;
		}

	}
	catch(e){
		if (e.description != "")
		{
			alert("发生错误！\r\n错误码:" + dec2hex(e.number) + "\r\n" + "错误描述：" + e.description);
		}
		else
		{
			alert("错误码:" + dec2hex(e.number));
		}
		return null;
	}
}

/**********************************
 检测当前控件版本是否满足需求
 contrlVersion:要使用的控件版本
 返回值：0-满足要求，2-版本号位数不一致，3-不满足使用要求
 其他-错误码
 ************************************/
function CheckVerson(contrlVersion)
{
	try{
		if(!isIE())
		{
			var request = new Object();
			request.method = "CheckVerson";
			request.contrlVersion = contrlVersion;

			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("版本检测发生错误！" + "\r\n" + "错误描述：" + ret.errMsg);
					return ret.errcode;
				}
				else{
					return ret.resultMSG;
				}
			}
		}
		else{
			var RetVal =  plugin().CheckVerson(contrlVersion);

			return RetVal;
		}

	}
	catch(e){
		if (e.description != "")
		{
			alert("发生错误！\r\n错误码:" + dec2hex(e.number) + "\r\n" + "错误描述：" + e.description);
		}
		else
		{
			alert("错误码:" + dec2hex(e.number));
		}
		return dec2hex(e.number);
	}
}


/**********************************
 安装根证书
 返回值：0-成功
 其他-错误码
 ************************************/
function CertInstall()
{
	try{
		if(!isIE())
		{
			var request = new Object();
			request.method = "CertInstall";

			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("安装根证书发生错误！" + "\r\n" + "错误描述：" + ret.errMsg);
					return ret.errcode;
				}
				else{
					return ret.resultMSG;
				}
			}
		}
		else{
			var RetVal =  plugin().CertInstall();

			return RetVal;
		}

	}
	catch(e){
		if (e.description != "")
		{
			alert("安装根证书发生错误！\r\n错误码:" + dec2hex(e.number) + "\r\n" + "错误描述：" + e.description);
		}
		else
		{
			alert("错误码:" + dec2hex(e.number));
		}
		return dec2hex(e.number);
	}
}


/**********************************
 获取已安装根证书个数
 返回值：0-14，已安装的根证书个数，其他-错误码
 ************************************/
function IsCertsExist()
{
	try{
		if(!isIE())
		{
			var request = new Object();
			request.method = "IsCertsExist";

			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("发生错误！" + "\r\n" + "错误描述：" + ret.errMsg);
					return ret.errcode;
				}
				else{
					return ret.resultMSG;
				}
			}
		}
		else{
			var RetVal =  plugin().IsCertsExist();

			return RetVal;
		}

	}
	catch(e){
		if (e.description != "")
		{
			alert("发生错误！\r\n错误码:" + dec2hex(e.number) + "\r\n" + "错误描述：" + e.description);
		}
		else
		{
			alert("错误码:" + dec2hex(e.number));
		}
		return dec2hex(e.number);
	}
}



/**********************************
 检测当前控件版本下各组件版本是否正确
 返回值：0-成功，其他-错误码
 ************************************/
function CheckContrlFile()
{
	try{
		if(!isIE())
		{
			var request = new Object();
			request.method = "CheckContrlFile";

			AjaxIO(JSON.stringify(request));

			var ret = GetHttpResult();
			if (ret) {
				if (ret.errcode != 0) {
					alert("发生错误！" + "\r\n" + "错误描述：" + ret.errMsg);
					return dec2hex(ret.errcode);
				}
				else{
					return ret.resultMSG;
				}
			}
		}
		else{
			var RetVal =  plugin().CheckContrlFile();

			return RetVal;
		}

	}
	catch(e){
		if (e.description != "")
		{
			alert("发生错误！\r\n错误码:" + dec2hex(e.number) + "\r\n" + "错误描述：" + e.description);
		}
		else
		{
			alert("错误码:" + dec2hex(e.number));
		}
		return dec2hex(e.number);
	}
}

/*************
 获取证书序列号
 *******************/
function getSerialNumber()
{
	var certdata = getCert("CCITCont1", AT_SIGNATURE);
	if(certdata == "" || certdata == null)
	{
		return "";
	}
	var serialNumber = getCertSN(certdata);
	return serialNumber;
}

/*********************
 功能：虚拟RA管理员证书下载
 **********************/
function downloadManagerCert(packdata)
{
	try{

		if(plugin().DownloadSingleCert(packdata, "sfsfsdf") == 0)
		{
			return true;
		}
	}
	catch(e){

		if (e.description != "")
		{
			alert(e.description);
			this.blur();
			this.focus();
		}

		return false;
	}
}

